﻿ if object_id('v_Utility_Asset_XmissionStructureImages') is not null
	drop view v_Utility_Asset_XmissionStructureImages

GO

create view v_Utility_Asset_XmissionStructureImages as

select

	 structures.Utility_Asset_XMissionStructureId as StructureId
	,images.Utility_Asset_XMissionStructures_ImageId as ImageId
	,Row_Number() over(partition by structures.Utility_Asset_XMissionStructureId order by images.Utility_Asset_XMissionStructures_ImageId) as ImageRank

from

	-- structure
	tb_Utility_Asset_XMissionStructures structures

	-- images
	left join tb_Utility_Asset_XMissionStructures_Images images
		on images.Utility_Asset_XMissionStructureFK = structures.Utility_Asset_XMissionStructureId 

GO

select TOP 10 * from v_Utility_Asset_XmissionStructureImages